Skip to content

Snapshot example services' GraphQL schemas as insta tests#6542

Closed
ma2bd wants to merge 4 commits into
mainfrom
ma2bd/graphql-schema-snapshot
Closed

Snapshot example services' GraphQL schemas as insta tests#6542
ma2bd wants to merge 4 commits into
mainfrom
ma2bd/graphql-schema-snapshot

Conversation

@ma2bd

@ma2bd ma2bd commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Motivation

We already record each application's serde/BCS formats as an insta snapshot (via the BcsApplication trait) so that unintended changes to the wire format of operations, messages and events show up as a reviewable diff. The GraphQL schema exposed by an application's service has no equivalent guard: today nothing flags an accidental change to the query/mutation surface that clients depend on.

Proposal

Establish a lightweight, purely conventional pattern (no new trait, no macro) for snapshotting a service's GraphQL schema, and apply it to hex-game as the reference implementation.

Unlike BcsApplication::formats(), which is type-only, building an async-graphql Schema needs owned instances of the roots and a ServiceRuntime — so the natural home is a #[cfg(test)] unit test in service.rs, where ServiceRuntime resolves to MockServiceRuntime. Concretely, for hex-game:

  • Extract HexService::schema() and have handle_query delegate to it, so the snapshotted SDL cannot drift from what the service actually serves.
  • Add a schema_sdl test: insta::assert_snapshot!(service.schema().sdl()), reusing the existing mock-runtime setup.
  • Commit the resulting SDL snapshot.
  • Apply the pattern the other GraphQL example services.

Test Plan

  • cargo test -p hex-game --bin hex_game_service — both query and the new schema_sdl pass.
  • Re-ran schema_sdl against the committed snapshot without INSTA_UPDATE to confirm the SDL is deterministic (the MapView hash-suffixed type names are stable across runs).
  • cargo fmt -- --check (pinned nightly) and cargo clippy -p hex-game --tests both clean.

Release Plan

  • Nothing to do / These changes follow the usual release cycle.

Links

@ma2bd ma2bd marked this pull request as ready for review June 20, 2026 21:53
@ma2bd ma2bd changed the title Snapshot the hex-game service GraphQL schema as an insta test Snapshot example services' GraphQL schemas as insta tests Jun 20, 2026

@deuszx deuszx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the description is outdated(?) since you added this pattern for all examples?

Also, why not add the fn schema() to trait ServiceAbi?

@ma2bd

ma2bd commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

I think the description is outdated(?) since you added this pattern for all examples?

Yes thx, I keep reminding Claude to do that

Also, why not add the fn schema() to trait ServiceAbi?

Because in theory, an app doesn't have to use GraphQL. It's just a convention that most (Wasm) apps use (like BCS) but it's not part of the core protocol.

@afck

afck commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

(I guess we could have a GraphQlServiceAbi: ServiceAbi trait, so some apps could use that one.)

@deuszx

deuszx commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Because in theory, an app doesn't have to use GraphQL. It's just a convention that most (Wasm) apps use (like BCS) but it's not part of the core protocol.

But we have (for example) impl Service for HexService that returns GraphQL schema. If we already have all(?) apps use it then we could make it "official" and easier to discover

@ma2bd

ma2bd commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

(I guess we could have a GraphQlServiceAbi: ServiceAbi trait, so some apps could use that one.)

Yes this could work. And also BcsContractAbi I suppose.

@ma2bd ma2bd closed this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants